import { Http } from '../../utils/http'
import { Order } from '../../model/Order'

Page({

  data: {
    tabs: [{
      id: 0,
      name: "全部",
      isActive: true,
      start:"token"
    },
    {
      id: 1,
      name: "今天",
      isActive: false,
      start:"today"
    },
    {
      id: 2,
      name: "昨天",
      isActive: false,
      start:"yesterday"
    },
    {
      id: 3,
      name: "近七日",
      isActive: false,
      start:"week"
    }],
    list:[]
  },

  ////获取 核销员业绩统计
  time: async function (e) {
    let result;
    const { index } = e.currentTarget.dataset.id;
    let { tabs } = this.data;
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
    this.setData({
      tabs
    });
    if(e.currentTarget.dataset.id == 0){
      //获取 核销员业绩统计
      result = await Order.get_distributor_statistics(null,'all');
    }else{
      //获取 核销员业绩统计
      result = await Order.get_distributor_statistics(null,e.currentTarget.dataset.start);
    }
    if(result.code == 0){
      this.setData({
        list:result.data
      })
    }else{
      console.log(result.msg);
    }
  },

  //生命周期函数--监听页面加载
  onLoad:async function (options) {
    let result = await Order.get_distributor_statistics(null,'all');
    if(result.code == 0){
      this.setData({
        list:result.data
      })
    }else{
      console.log(result.msg);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})